'
\ufeffLAB: Exceptions with vectors
Complete a program that reads a vector index as input and outputs the element of a vector of \ufeffnames at the index specified by the input. Use a try block to output the name and a catch block to catch any outofrange exceptions. When an outofrange exception is caught, output the message from the exception object and the first element in the vector if the index is negative or the last element if the index is greater than the size of the vector.
Hint: Format the exception outputs using the what \ufefffunction from the exception object. Do not hard code the exception messages.
Ex: If the input of the program is:
the program outputs:
Jane
Ex: If the input of the program is:
the program outputs:
Exception! vector::Mrangecheck: n which is \ufeffthissizewhich is
The closest name is: Johnny
Ex: If the input of the program is:
the program outputs:
Exception! vector::Mrangecheck: n which is \ufeffthissizewhich is
The closest name is: Ryley #include
#include
#include \ufeffFor std::outofrange
using namespace std;
int main
\ufeff vector names \ufeff"Ryley", "Edan", "Reagan", "Henry", "Caius", "Jane", "Guto", "Sonya", "Tyrese", "Johnny" ;
\ufeff int index;
\ufeff cin \ufeffindex;
\ufeff
\ufeff \ufeffType your code here.
\ufeff return ;
'